package juejin;

public class ThreadDemo {

    public static void main(String[] args) throws InterruptedException {
        ThreadDemo.testWaitNotify();
    }

    private static void testWaitNotify() throws InterruptedException {
        Object lock = new Object();
        new Thread(() -> {
            synchronized (lock) {
                try {
                    System.out.println("wait之前...");
                    lock.wait();
                    System.out.println("wait之后...");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();

        Thread.sleep(2000);
        synchronized (lock) {
            System.out.println("执行notify...");
            lock.notify();
        }
    }

}
